﻿using System;
using System.Collections.Generic;

namespace ProblemsSet
{
    public class Problem_87 : BaseProblem
    {
        public override object GetResult()
        {
            const int max = 50000000;
            //const int max = 50;

            var lstQtr = MathLogic.GetPrimeList((long) (Math.Pow(max, 1/(double) 4)) + 1, true);
            var lstCub = MathLogic.GetPrimeList((long)(Math.Pow(max, 1 / (double)3)) + 1, true);
            var lstSqr = MathLogic.GetPrimeList((long)(Math.Pow(max, 1 / (double)2)) + 1, true);

            var hs = new HashSet<long>();

            foreach (var l in lstQtr)
            {
                foreach (var l1 in lstCub)
                {
                    long cur = l*l*l*l + l1*l1*l1;
                    if (cur > max) break;
                    foreach (var l2 in lstSqr)
                    {
                        long tmp = cur + l2*l2;
                        if (tmp > max) break;
                        if (!hs.Contains(tmp)) hs.Add(tmp);
                    }
                }
            }
            return hs.Count;
        }

        public override string Problem
        {
            get
            {
                return @"The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is 28. In fact, there are exactly four numbers below fifty that can be expressed in such a way:

28 = 22 + 23 + 24
33 = 32 + 23 + 24
49 = 52 + 23 + 24
47 = 22 + 33 + 24
How many numbers below fifty million can be expressed as the sum of a prime square, prime cube, and prime fourth power?";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 1097343;
            }
        }

    }
}
